{extend name="index/base" /}

{block name="menu"}
{load href="/static/index/js/jquery.min.js"}

<div class="tpl-content-wrapper">
    <div class="tpl-content-page-title">
        商家管理
    </div>
    <ol class="am-breadcrumb">
        <li><a href="#" class="am-icon-home">首页</a></li>
        <li><a href="#">商家管理</a></li>
        <li class="am-active">商家列表</li>
    </ol>
    <div class="tpl-portlet-components">
        <div class="portlet-title">
            <div class="caption font-green bold">
                <span class="am-icon-code">{$title}</span>
            </div>

            <div class="tpl-portlet-input tpl-fz-ml">
                <div class="portlet-input input-small input-inline">
                    <div class="input-icon right">
                        <i class="am-icon-search" id="select-bn" style="cursor:pointer"></i>
                        <input type="text" id="select-bnn" class="form-control form-control-solid" placeholder="请输入商家名" >
                    </div>
                </div>
            </div>
            <!--搜索-->
            <script>
                $('#select-bn').click(function(){
                    var bnn = $('#select-bnn').val();
                    $.ajax({
                        type:'post',
                        data:{'bnn':bnn},
                        url:'index/select',
                        success:function(data){
                            //跳转到一个页面
                            console.log(data);
                            $('.bnn-tr').remove();
                            $('.pagination').remove();
                            var bnn_tr='';
                            for (var i in data ){
                                console.log(data[i]);
                                bnn_tr=bnn_tr+'<tr class="bnn-tr">'+
                                   ' <td><input type="checkbox"></td>'+
                                   ' <td>'+data[i].id+'</td>'+
                                '<td><a href="#">'+data[i].name+'</a></td>'+
                                '<td>'+data[i].site+'</td>'+
                               ' <td class="am-hide-sm-only">'+data[i].dns+'</td>'+
                               ' <td class="am-hide-sm-only">'+data[i].ptime+'</td>'+
                               ' <td class="am-hide-sm-only">'+data[i].ip+'</td>'+
                                '<td>'+
                                '<div class="am-btn-toolbar">'+
                                    '<div class="am-btn-group am-btn-group-xs">'+
                                   ' <a class="am-btn am-btn-default am-btn-xs am-text-secondary" href="http://www.xmtp.com/gl/'+data[i].id+'/edit.html"><span class="am-icon-pencil-square-o"></span> 编辑</a>'+
                                    '<button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only bbb-bb" onclick="del(this)" data-t="'+data[i].id+'">删除</button>'+
                                    '</div>'+
                                    '</div>'+
                                    '</td>'+
                                   ' </tr>';
                            }
                            console.log(bnn_tr);
                            $('#bnn-tb').html(bnn_tr);
                        },
                        error:function(){
                            alert('失败');
                        }
                    })
                })
            </script>

        </div>
        <!--http://www.xmtp.com/gl/4/edit.html-->
        <!--/index/gl/edit.html-->

        <div class="tpl-block">
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a type="button" class="am-btn am-btn-default am-btn-success" href="{:url('index/gl/create')}"><span class="am-icon-plus"></span> 新增</a>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-form-group">

                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-input-group am-input-group-sm">

                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>

                            <!--content start-->
                            <tr>
                                <th class="table-check"><input type="checkbox" class="tpl-table-fz-check"></th>
                                <th class="table-id">ID</th>
                                <th class="table-title">商家名</th>
                                <th class="table-type">站点名</th>
                                <th class="table-author am-hide-sm-only">域名</th>
                                <th class="table-date am-hide-sm-only">购买时间</th>
                                <th class="table-date am-hide-sm-only">购买时长</th>
                                <th class="table-set">IP地址</th>

                            </tr>
                            <!--content stop-->
                            </thead>
                            <tbody id="bnn-tb">

                            {volist name="list" id="vo"}
                            <tr class="bnn-tr">
                                <td><input type="checkbox"></td>
                                <td>{$vo.id}</td>
                                <td><a href="#">{$vo.name}</a></td>
                                <td>{$vo.site}</td>
                                <td class="am-hide-sm-only">{$vo.dns}</td>
                                <td class="am-hide-sm-only">{:date("Y-m-d",$vo.btime)}</td>
                                <td class="am-hide-sm-only">{$vo.ptime}</td>
                                <td class="am-hide-sm-only">{$vo.ip}</td>
                                <td>
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a class="am-btn am-btn-default am-btn-xs am-text-secondary" href="{:url('index/gl/edit',['id'=>$vo.id])}"><span class="am-icon-pencil-square-o"></span> 编辑</a>
                                            <button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only " onclick="changeStatus(this)" data-m="{$vo.id}">
                                                {if $vo.status == 1}
                                                 禁用
                                                {else}
                                                 激活
                                                {/if}
                                            </button>
                                            <button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only bbb-bb" onclick="del(this)" data-t="{$vo.id}">删除</button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        <!--禁用-->
                        <script>
                            function changeStatus(aaa){
                                var data = $(aaa).attr('data-m');
                                var _this = $(aaa);
                                var nnn =  _this.html();
//                                console.log(data);
//                                console.log(_this);
                                console.log(nnn);
                                $.ajax({
                                    type:'post',
                                    url:'gl/changeStatus',
                                    data:{'id':data},
                                    synsc:'true',
                                    success:function(status){
                                        if(status){
                                            if(status == '0'){
//                                                alert('11');
                                                _this.html('激活');
                                            }else if(status == '1'){
//                                                alert('22');
                                                _this.html('禁用');
                                            }else{
                                                alert('无权限,更改失败');
                                            }
                                        }
                                    },
                                    error:function(){
                                        alert('失败');
                                    }
                                });
                            }
                        </script>


                        <div class="am-cf">
                            <div class="am-fr" >
                                <style>
                                    .pagination li{
                                        float:left;
                                        margin-right:20px;
                                    }
                                </style>
                                {$list->render()}
                            </div>
                        </div>
                        <hr>

                    </form>
                </div>

            </div>
        </div>
        <div class="tpl-alert"></div>

    </div>

</div>

<script>


    function del(aaa) {
//        console.log(aaa);
        var data = $(aaa).attr('data-t');
//        console.log(data);
        var _this = $(aaa);
        $.ajax({
            type:'delete',
            url:'gl/'+data,
            synsc:'true',
            success:function(aa){
                if(aa){
                    _this.parents('tr').remove();
                    alert('删除成功');
                }
            },
            error:function(){
                alert('删除失败');
            }
        });

    };
</script>

{/block}



